package org.autumn.review.thread;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.ReentrantLock;

@Slf4j
public class ReentrantLockTest {

    private static final ReentrantLock lock = new ReentrantLock();
    public static void main(String[] args) {
        testCondition();
    }

    private static void testCondition() {
        Condition condition = lock.newCondition();
        Thread t1 = new Thread(() -> {
            lock.lock();
            try {
                condition.await();
                log.info("1111111");
            } catch (InterruptedException e) {
                e.printStackTrace();
            } finally {
                lock.unlock();
            }

        }, "t1");
        t1.start();

        Thread t2 = new Thread(() -> {
            lock.lock();
            try {
                log.info("1111111");
                condition.signalAll();
            } finally {
                lock.unlock();
            }
        }, "t2");
        t2.start();
    }
}
